package com.bytedance.touch.remote

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : Activity(){

    private var start = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btn_start.text = "start"
        btn_start.setOnClickListener {
            val intent = Intent(this, WorkService::class.java)
            if (!start){
                start = true
                btn_start.text = "stop"
                startWorkService(intent)
            } else {
                start = false
                btn_start.text = "start"
                stopWorkService(intent)
            }

        }
    }

    private fun stopWorkService(intent: Intent) {
        stopService(intent)
    }

    private fun startWorkService(intent: Intent){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            startForegroundService(intent)
        } else {
            startService(intent)
        }
    }
}